package com.kaishengit.web;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.kaishengit.entity.Goal;
import com.kaishengit.entity.Project;
import com.kaishengit.entity.Task;
import com.kaishengit.service.GoalService;
import com.kaishengit.service.TaskService;

public class GoalListView extends HttpServlet {

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		request.setCharacterEncoding("UTF-8");
		
		String projectname = request.getParameter("project");
		if(projectname!=null) {
			request.setAttribute("projectname", projectname);
		}
		
		
		GoalService goalService = new GoalService();
		
		TaskService taskService = new TaskService();
		
		List<Goal>  listgoal = goalService.findGoalnamesByProjectname(projectname);
		
		HashMap numbers = new HashMap();
		
		
		for(Goal goal : listgoal) {
			List<Task> listtask = taskService.findTasknamesByGoalname(goal.getName(),projectname);
			numbers.put(goal.getName(),listtask);
		}
		
		request.setAttribute("numbers", numbers);
		request.setAttribute("listgoal",listgoal);
		
		request.getRequestDispatcher("WEB-INF/views/goallist.jsp").forward(request, response);
		
	}

}
